package com.hrserviceserve.config;

import com.hrserviceserve.utils.Appconfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private Appconfig appConfig;
    /**
     * 静态资源处理
     **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //appConfig.getResPhysicalPath() 这表示项目所在的文件夹，下面会有介绍
        String webPath = appConfig.getResPhysicalPath();

        File file = new File(webPath + "/logistics/");
        if (!file.exists()) {
            file.mkdirs();
        }
        System.out.println("静态资源处理：" + webPath + "/logistics/");

        registry.addResourceHandler("/logistics/**").addResourceLocations("file:" +  "/logistics/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

}
